<?php
declare(strict_types=1);
namespace Field;

class SysMenuConst
{
    public const pk='';
    public const index=['Node','ParentNode','Method'];
	public const fields=['Node','ParentNode','Method','Name','Rank','Hidden','Component','Active','Affix','TypeId','Icon','Login','Auth','Menu'];
	public const comment=['Node'=>'节点','ParentNode'=>'上层节点','Method'=>'GET, POST,PUT, DELETE','Name'=>'菜单名称','Rank'=>'排序','Hidden'=>'','Component'=>'','Active'=>'','Affix'=>'','TypeId'=>'类型：菜单，Iframe，外链，按钮','Icon'=>'','Login'=>'需要登录','Auth'=>'需要鉴权','Menu'=>'是否菜单'];
	/*
    * @Field Node
    * @Type varchar(64)
    * @Collation utf8mb4_general_ci
    * @Null NO
    * @Key PRI
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 节点
    */
    public const Node = 'Node';
    /*
    * @Field ParentNode
    * @Type varchar(64)
    * @Collation utf8mb4_general_ci
    * @Null NO
    * @Key PRI
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 上层节点
    */
    public const ParentNode = 'ParentNode';
    /*
    * @Field Method
    * @Type varchar(16)
    * @Collation utf8mb4_general_ci
    * @Null NO
    * @Key PRI
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment GET, POST,PUT, DELETE
    */
    public const Method = 'Method';
    /*
    * @Field Name
    * @Type varchar(64)
    * @Collation utf8mb4_general_ci
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 菜单名称
    */
    public const Name = 'Name';
    /*
    * @Field Rank
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 排序
    */
    public const Rank = 'Rank';
    /*
    * @Field Hidden
    * @Type int(10)
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Hidden = 'Hidden';
    /*
    * @Field Component
    * @Type varchar(64)
    * @Collation utf8mb4_general_ci
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Component = 'Component';
    /*
    * @Field Active
    * @Type int(10)
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Active = 'Active';
    /*
    * @Field Affix
    * @Type int(10)
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Affix = 'Affix';
    /*
    * @Field TypeId
    * @Type varchar(32)
    * @Collation utf8mb4_general_ci
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 类型：菜单，Iframe，外链，按钮
    */
    public const TypeId = 'TypeId';
    /*
    * @Field Icon
    * @Type varchar(32)
    * @Collation utf8mb4_general_ci
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Icon = 'Icon';
    /*
    * @Field Login
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 需要登录
    */
    public const Login = 'Login';
    /*
    * @Field Auth
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 需要鉴权
    */
    public const Auth = 'Auth';
    /*
    * @Field Menu
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 是否菜单
    */
    public const Menu = 'Menu';
}

class SysMenuColumns
{
public  string $Node;
   public  string $ParentNode;
   public  string $Method;
   public  ?string $Name='';
   public  int $Rank=0;
   public  int $Hidden=0;
   public  ?string $Component='';
   public  int $Active=0;
   public  int $Affix=0;
   public  ?string $TypeId='';
   public  ?string $Icon='';
   public  int $Login=0;
   public  int $Auth=0;
   public  int $Menu=0;
	public function toArray():array
	{
		return [
'Node'=>$this->Node,
    'ParentNode'=>$this->ParentNode,
    'Method'=>$this->Method,
    'Name'=>$this->Name,
    'Rank'=>$this->Rank,
    'Hidden'=>$this->Hidden,
    'Component'=>$this->Component,
    'Active'=>$this->Active,
    'Affix'=>$this->Affix,
    'TypeId'=>$this->TypeId,
    'Icon'=>$this->Icon,
    'Login'=>$this->Login,
    'Auth'=>$this->Auth,
    'Menu'=>$this->Menu,        ];
	}
}

class SysMenuRow
{
	public SysMenuColumns $data;
	public function toArray():array
	{
		return $this->data->toArray();
    }

    public function getValue(string $field):string|int|null
    {
        return match ($field){
        'Node' => $this->data->Node,
        'ParentNode' => $this->data->ParentNode,
        'Method' => $this->data->Method,
        'Name' => $this->data->Name,
        'Rank' => $this->data->Rank,
        'Hidden' => $this->data->Hidden,
        'Component' => $this->data->Component,
        'Active' => $this->data->Active,
        'Affix' => $this->data->Affix,
        'TypeId' => $this->data->TypeId,
        'Icon' => $this->data->Icon,
        'Login' => $this->data->Login,
        'Auth' => $this->data->Auth,
        'Menu' => $this->data->Menu, default=>null
        };
    }

    public function __construct(array $data)
    {
        $this->data = new SysMenuColumns();
        isset($data['Node']) && $this->data->Node = (string)$data['Node'];
           isset($data['ParentNode']) && $this->data->ParentNode = (string)$data['ParentNode'];
           isset($data['Method']) && $this->data->Method = (string)$data['Method'];
           isset($data['Name']) && $this->data->Name = (string)$data['Name'];
           isset($data['Rank']) && $this->data->Rank = (int)$data['Rank'];
           isset($data['Hidden']) && $this->data->Hidden = (int)$data['Hidden'];
           isset($data['Component']) && $this->data->Component = (string)$data['Component'];
           isset($data['Active']) && $this->data->Active = (int)$data['Active'];
           isset($data['Affix']) && $this->data->Affix = (int)$data['Affix'];
           isset($data['TypeId']) && $this->data->TypeId = (string)$data['TypeId'];
           isset($data['Icon']) && $this->data->Icon = (string)$data['Icon'];
           isset($data['Login']) && $this->data->Login = (int)$data['Login'];
           isset($data['Auth']) && $this->data->Auth = (int)$data['Auth'];
           isset($data['Menu']) && $this->data->Menu = (int)$data['Menu'];
    }
}
?>